{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"http://hilpisch.com/tpq_logo.png\" alt=\"The Python Quants\" width=\"35%\" align=\"right\" border=\"0\"><br>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Financial Theory with Python\n",
    "**&mdash;A Gentle Introduction**\n",
    "\n",
    "Dr Yves J Hilpisch | The Python Quants | The AI Machine\n",
    "\n",
    "http://tpq.io | http://aimachine.io | [@dyjh](http://twitter.com/dyjh)\n",
    "\n",
    "<img src=\"https://hilpisch.com/finpy_cover.png\" width=30% border=1px align=left>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Chapter 04 &mdash; Optimality and Equilibrium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Utility Maximization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def u(c):\n",
    "    return -c[0] * c[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "w = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy.optimize import minimize"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "cons = ({'type': 'eq', 'fun': lambda c: c[0] + c[1] - w})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "opt = minimize(u, (1, 1), constraints=cons)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "     fun: -24.999999999999996\n",
       "     jac: array([-5., -5.])\n",
       " message: 'Optimization terminated successfully'\n",
       "    nfev: 6\n",
       "     nit: 2\n",
       "    njev: 2\n",
       "  status: 0\n",
       " success: True\n",
       "       x: array([5., 5.])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "opt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5., 5.])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "opt['x']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "24.999999999999996"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "-opt['fun'] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def iu(u, c0):\n",
    "    return u / c0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def c1(c0):\n",
    "    return w - c0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "np.set_printoptions(precision=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pylab import mpl, plt\n",
    "plt.style.use('seaborn')\n",
    "mpl.rcParams['font.family'] = 'serif'\n",
    "%config InlineBackend.figure_formats = ['svg']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "c0 = np.linspace(1, w)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg height=\"357.238125pt\" version=\"1.1\" viewBox=\"0 0 592.125 357.238125\" width=\"592.125pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <metadata>\n",
       "  <rdf:RDF xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
       "   <cc:Work>\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
       "    <dc:date>2021-10-19T11:02:08.723270</dc:date>\n",
       "    <dc:format>image/svg+xml</dc:format>\n",
       "    <dc:creator>\n",
       "     <cc:Agent>\n",
       "      <dc:title>Matplotlib v3.4.1, https://matplotlib.org/</dc:title>\n",
       "     </cc:Agent>\n",
       "    </dc:creator>\n",
       "   </cc:Work>\n",
       "  </rdf:RDF>\n",
       " </metadata>\n",
       " <defs>\n",
       "  <style type=\"text/css\">*{stroke-linecap:butt;stroke-linejoin:round;}</style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 357.238125 \n",
       "L 592.125 357.238125 \n",
       "L 592.125 0 \n",
       "L 0 0 \n",
       "z\n",
       "\" style=\"fill:#ffffff;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path d=\"M 26.925 333.36 \n",
       "L 584.925 333.36 \n",
       "L 584.925 7.2 \n",
       "L 26.925 7.2 \n",
       "z\n",
       "\" style=\"fill:#eaeaf2;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\">\n",
       "    <g id=\"xtick_1\">\n",
       "     <g id=\"line2d_1\">\n",
       "      <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 108.652273 333.36 \n",
       "L 108.652273 7.2 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_2\"/>\n",
       "     <g id=\"text_1\">\n",
       "      <!-- 2 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(105.471023 347.958438)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path d=\"M 819 3553 \n",
       "L 469 3553 \n",
       "L 469 4384 \n",
       "Q 803 4563 1142 4656 \n",
       "Q 1481 4750 1806 4750 \n",
       "Q 2534 4750 2956 4397 \n",
       "Q 3378 4044 3378 3438 \n",
       "Q 3378 2753 2422 1800 \n",
       "Q 2347 1728 2309 1691 \n",
       "L 1131 513 \n",
       "L 3078 513 \n",
       "L 3078 1088 \n",
       "L 3444 1088 \n",
       "L 3444 0 \n",
       "L 434 0 \n",
       "L 434 341 \n",
       "L 1850 1753 \n",
       "Q 2319 2222 2519 2614 \n",
       "Q 2719 3006 2719 3438 \n",
       "Q 2719 3909 2473 4175 \n",
       "Q 2228 4441 1797 4441 \n",
       "Q 1350 4441 1106 4219 \n",
       "Q 863 3997 819 3553 \n",
       "z\n",
       "\" id=\"DejaVuSerif-32\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSerif-32\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_3\">\n",
       "      <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 221.379545 333.36 \n",
       "L 221.379545 7.2 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_4\"/>\n",
       "     <g id=\"text_2\">\n",
       "      <!-- 4 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(218.198295 347.958438)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path d=\"M 2234 1581 \n",
       "L 2234 4063 \n",
       "L 641 1581 \n",
       "L 2234 1581 \n",
       "z\n",
       "M 3609 0 \n",
       "L 1484 0 \n",
       "L 1484 331 \n",
       "L 2234 331 \n",
       "L 2234 1247 \n",
       "L 197 1247 \n",
       "L 197 1588 \n",
       "L 2241 4750 \n",
       "L 2859 4750 \n",
       "L 2859 1581 \n",
       "L 3750 1581 \n",
       "L 3750 1247 \n",
       "L 2859 1247 \n",
       "L 2859 331 \n",
       "L 3609 331 \n",
       "L 3609 0 \n",
       "z\n",
       "\" id=\"DejaVuSerif-34\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSerif-34\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_5\">\n",
       "      <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 334.106818 333.36 \n",
       "L 334.106818 7.2 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_6\"/>\n",
       "     <g id=\"text_3\">\n",
       "      <!-- 6 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(330.925568 347.958438)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path d=\"M 2094 219 \n",
       "Q 2534 219 2771 542 \n",
       "Q 3009 866 3009 1472 \n",
       "Q 3009 2078 2771 2401 \n",
       "Q 2534 2725 2094 2725 \n",
       "Q 1647 2725 1412 2412 \n",
       "Q 1178 2100 1178 1509 \n",
       "Q 1178 888 1415 553 \n",
       "Q 1653 219 2094 219 \n",
       "z\n",
       "M 1075 2569 \n",
       "Q 1288 2803 1556 2918 \n",
       "Q 1825 3034 2163 3034 \n",
       "Q 2859 3034 3264 2615 \n",
       "Q 3669 2197 3669 1472 \n",
       "Q 3669 763 3233 336 \n",
       "Q 2797 -91 2069 -91 \n",
       "Q 1278 -91 853 498 \n",
       "Q 428 1088 428 2181 \n",
       "Q 428 3406 931 4078 \n",
       "Q 1434 4750 2350 4750 \n",
       "Q 2597 4750 2869 4703 \n",
       "Q 3141 4656 3425 4563 \n",
       "L 3425 3794 \n",
       "L 3072 3794 \n",
       "Q 3034 4109 2831 4275 \n",
       "Q 2628 4441 2284 4441 \n",
       "Q 1678 4441 1381 3981 \n",
       "Q 1084 3522 1075 2569 \n",
       "z\n",
       "\" id=\"DejaVuSerif-36\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSerif-36\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_7\">\n",
       "      <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 446.834091 333.36 \n",
       "L 446.834091 7.2 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_8\"/>\n",
       "     <g id=\"text_4\">\n",
       "      <!-- 8 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(443.652841 347.958438)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path d=\"M 2981 1275 \n",
       "Q 2981 1775 2732 2051 \n",
       "Q 2484 2328 2034 2328 \n",
       "Q 1584 2328 1336 2051 \n",
       "Q 1088 1775 1088 1275 \n",
       "Q 1088 772 1336 495 \n",
       "Q 1584 219 2034 219 \n",
       "Q 2484 219 2732 495 \n",
       "Q 2981 772 2981 1275 \n",
       "z\n",
       "M 2853 3541 \n",
       "Q 2853 3966 2637 4203 \n",
       "Q 2422 4441 2034 4441 \n",
       "Q 1650 4441 1433 4203 \n",
       "Q 1216 3966 1216 3541 \n",
       "Q 1216 3113 1433 2875 \n",
       "Q 1650 2638 2034 2638 \n",
       "Q 2422 2638 2637 2875 \n",
       "Q 2853 3113 2853 3541 \n",
       "z\n",
       "M 2516 2484 \n",
       "Q 3047 2413 3344 2092 \n",
       "Q 3641 1772 3641 1275 \n",
       "Q 3641 619 3225 264 \n",
       "Q 2809 -91 2034 -91 \n",
       "Q 1263 -91 845 264 \n",
       "Q 428 619 428 1275 \n",
       "Q 428 1772 725 2092 \n",
       "Q 1022 2413 1556 2484 \n",
       "Q 1084 2569 832 2842 \n",
       "Q 581 3116 581 3541 \n",
       "Q 581 4103 968 4426 \n",
       "Q 1356 4750 2034 4750 \n",
       "Q 2713 4750 3100 4426 \n",
       "Q 3488 4103 3488 3541 \n",
       "Q 3488 3116 3236 2842 \n",
       "Q 2984 2569 2516 2484 \n",
       "z\n",
       "\" id=\"DejaVuSerif-38\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSerif-38\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_9\">\n",
       "      <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 559.561364 333.36 \n",
       "L 559.561364 7.2 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_10\"/>\n",
       "     <g id=\"text_5\">\n",
       "      <!-- 10 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(553.198864 347.958438)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path d=\"M 909 0 \n",
       "L 909 331 \n",
       "L 1722 331 \n",
       "L 1722 4213 \n",
       "L 781 3603 \n",
       "L 781 4013 \n",
       "L 1919 4750 \n",
       "L 2350 4750 \n",
       "L 2350 331 \n",
       "L 3163 331 \n",
       "L 3163 0 \n",
       "L 909 0 \n",
       "z\n",
       "\" id=\"DejaVuSerif-31\" transform=\"scale(0.015625)\"/>\n",
       "        <path d=\"M 2034 219 \n",
       "Q 2513 219 2750 744 \n",
       "Q 2988 1269 2988 2328 \n",
       "Q 2988 3391 2750 3916 \n",
       "Q 2513 4441 2034 4441 \n",
       "Q 1556 4441 1318 3916 \n",
       "Q 1081 3391 1081 2328 \n",
       "Q 1081 1269 1318 744 \n",
       "Q 1556 219 2034 219 \n",
       "z\n",
       "M 2034 -91 \n",
       "Q 1275 -91 848 546 \n",
       "Q 422 1184 422 2328 \n",
       "Q 422 3475 848 4112 \n",
       "Q 1275 4750 2034 4750 \n",
       "Q 2797 4750 3222 4112 \n",
       "Q 3647 3475 3647 2328 \n",
       "Q 3647 1184 3222 546 \n",
       "Q 2797 -91 2034 -91 \n",
       "z\n",
       "\" id=\"DejaVuSerif-30\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSerif-31\"/>\n",
       "       <use x=\"63.623047\" xlink:href=\"#DejaVuSerif-30\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_11\">\n",
       "      <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 26.925 318.534545 \n",
       "L 584.925 318.534545 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_12\"/>\n",
       "     <g id=\"text_6\">\n",
       "      <!-- 0 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(13.5625 322.333764)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSerif-30\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_13\">\n",
       "      <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 26.925 276.176104 \n",
       "L 584.925 276.176104 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_14\"/>\n",
       "     <g id=\"text_7\">\n",
       "      <!-- 5 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(13.5625 279.975323)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path d=\"M 3219 4666 \n",
       "L 3219 4153 \n",
       "L 1081 4153 \n",
       "L 1081 2816 \n",
       "Q 1244 2928 1461 2984 \n",
       "Q 1678 3041 1947 3041 \n",
       "Q 2703 3041 3140 2622 \n",
       "Q 3578 2203 3578 1478 \n",
       "Q 3578 738 3136 323 \n",
       "Q 2694 -91 1894 -91 \n",
       "Q 1572 -91 1234 -12 \n",
       "Q 897 66 544 225 \n",
       "L 544 1131 \n",
       "L 897 1131 \n",
       "Q 925 688 1179 453 \n",
       "Q 1434 219 1894 219 \n",
       "Q 2388 219 2653 544 \n",
       "Q 2919 869 2919 1478 \n",
       "Q 2919 2084 2655 2407 \n",
       "Q 2391 2731 1894 2731 \n",
       "Q 1613 2731 1398 2631 \n",
       "Q 1184 2531 1019 2322 \n",
       "L 750 2322 \n",
       "L 750 4666 \n",
       "L 3219 4666 \n",
       "z\n",
       "\" id=\"DejaVuSerif-35\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSerif-35\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_3\">\n",
       "     <g id=\"line2d_15\">\n",
       "      <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 26.925 233.817662 \n",
       "L 584.925 233.817662 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_16\"/>\n",
       "     <g id=\"text_8\">\n",
       "      <!-- 10 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(7.2 237.616881)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSerif-31\"/>\n",
       "       <use x=\"63.623047\" xlink:href=\"#DejaVuSerif-30\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_4\">\n",
       "     <g id=\"line2d_17\">\n",
       "      <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 26.925 191.459221 \n",
       "L 584.925 191.459221 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_18\"/>\n",
       "     <g id=\"text_9\">\n",
       "      <!-- 15 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(7.2 195.25844)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSerif-31\"/>\n",
       "       <use x=\"63.623047\" xlink:href=\"#DejaVuSerif-35\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_5\">\n",
       "     <g id=\"line2d_19\">\n",
       "      <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 26.925 149.100779 \n",
       "L 584.925 149.100779 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_20\"/>\n",
       "     <g id=\"text_10\">\n",
       "      <!-- 20 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(7.2 152.899998)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSerif-32\"/>\n",
       "       <use x=\"63.623047\" xlink:href=\"#DejaVuSerif-30\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_6\">\n",
       "     <g id=\"line2d_21\">\n",
       "      <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 26.925 106.742338 \n",
       "L 584.925 106.742338 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_22\"/>\n",
       "     <g id=\"text_11\">\n",
       "      <!-- 25 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(7.2 110.541556)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSerif-32\"/>\n",
       "       <use x=\"63.623047\" xlink:href=\"#DejaVuSerif-35\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_7\">\n",
       "     <g id=\"line2d_23\">\n",
       "      <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 26.925 64.383896 \n",
       "L 584.925 64.383896 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_24\"/>\n",
       "     <g id=\"text_12\">\n",
       "      <!-- 30 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(7.2 68.183115)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path d=\"M 622 4469 \n",
       "Q 988 4606 1323 4678 \n",
       "Q 1659 4750 1953 4750 \n",
       "Q 2638 4750 3022 4454 \n",
       "Q 3406 4159 3406 3634 \n",
       "Q 3406 3213 3140 2930 \n",
       "Q 2875 2647 2388 2547 \n",
       "Q 2963 2466 3280 2130 \n",
       "Q 3597 1794 3597 1259 \n",
       "Q 3597 606 3158 257 \n",
       "Q 2719 -91 1894 -91 \n",
       "Q 1528 -91 1179 -12 \n",
       "Q 831 66 488 225 \n",
       "L 488 1131 \n",
       "L 838 1131 \n",
       "Q 869 681 1141 450 \n",
       "Q 1413 219 1906 219 \n",
       "Q 2384 219 2661 495 \n",
       "Q 2938 772 2938 1253 \n",
       "Q 2938 1803 2653 2086 \n",
       "Q 2369 2369 1819 2369 \n",
       "L 1522 2369 \n",
       "L 1522 2688 \n",
       "L 1678 2688 \n",
       "Q 2225 2688 2498 2914 \n",
       "Q 2772 3141 2772 3597 \n",
       "Q 2772 4006 2547 4223 \n",
       "Q 2322 4441 1900 4441 \n",
       "Q 1478 4441 1245 4241 \n",
       "Q 1013 4041 972 3647 \n",
       "L 622 3647 \n",
       "L 622 4469 \n",
       "z\n",
       "\" id=\"DejaVuSerif-33\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSerif-33\"/>\n",
       "       <use x=\"63.623047\" xlink:href=\"#DejaVuSerif-30\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_8\">\n",
       "     <g id=\"line2d_25\">\n",
       "      <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 26.925 22.025455 \n",
       "L 584.925 22.025455 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_26\"/>\n",
       "     <g id=\"text_13\">\n",
       "      <!-- 35 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(7.2 25.824673)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSerif-33\"/>\n",
       "       <use x=\"63.623047\" xlink:href=\"#DejaVuSerif-35\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"line2d_27\">\n",
       "    <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 52.288636 242.289351 \n",
       "L 62.641141 243.845375 \n",
       "L 72.993646 245.401399 \n",
       "L 83.34615 246.957424 \n",
       "L 93.698655 248.513448 \n",
       "L 104.05116 250.069473 \n",
       "L 114.403664 251.625497 \n",
       "L 124.756169 253.181521 \n",
       "L 135.108673 254.737546 \n",
       "L 145.461178 256.29357 \n",
       "L 155.813683 257.849594 \n",
       "L 166.166187 259.405619 \n",
       "L 176.518692 260.961643 \n",
       "L 186.871197 262.517668 \n",
       "L 197.223701 264.073692 \n",
       "L 207.576206 265.629716 \n",
       "L 217.928711 267.185741 \n",
       "L 228.281215 268.741765 \n",
       "L 238.63372 270.29779 \n",
       "L 248.986224 271.853814 \n",
       "L 259.338729 273.409838 \n",
       "L 269.691234 274.965863 \n",
       "L 280.043738 276.521887 \n",
       "L 290.396243 278.077911 \n",
       "L 300.748748 279.633936 \n",
       "L 311.101252 281.18996 \n",
       "L 321.453757 282.745985 \n",
       "L 331.806262 284.302009 \n",
       "L 342.158766 285.858033 \n",
       "L 352.511271 287.414058 \n",
       "L 362.863776 288.970082 \n",
       "L 373.21628 290.526107 \n",
       "L 383.568785 292.082131 \n",
       "L 393.921289 293.638155 \n",
       "L 404.273794 295.19418 \n",
       "L 414.626299 296.750204 \n",
       "L 424.978803 298.306228 \n",
       "L 435.331308 299.862253 \n",
       "L 445.683813 301.418277 \n",
       "L 456.036317 302.974302 \n",
       "L 466.388822 304.530326 \n",
       "L 476.741327 306.08635 \n",
       "L 487.093831 307.642375 \n",
       "L 497.446336 309.198399 \n",
       "L 507.79884 310.754424 \n",
       "L 518.151345 312.310448 \n",
       "L 528.50385 313.866472 \n",
       "L 538.856354 315.422497 \n",
       "L 549.208859 316.978521 \n",
       "L 559.561364 318.534545 \n",
       "\" style=\"fill:none;stroke:#4c72b0;stroke-linecap:round;stroke-width:3;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_28\">\n",
       "    <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 52.288636 191.459221 \n",
       "L 62.641141 211.177806 \n",
       "L 72.993646 225.59886 \n",
       "L 83.34615 236.604402 \n",
       "L 93.698655 245.279358 \n",
       "L 104.05116 252.293153 \n",
       "L 114.403664 258.081236 \n",
       "L 124.756169 262.939091 \n",
       "L 135.108673 267.07429 \n",
       "L 145.461178 270.636923 \n",
       "L 155.813683 273.738208 \n",
       "L 166.166187 276.46231 \n",
       "L 176.518692 278.874094 \n",
       "L 186.871197 281.024359 \n",
       "L 197.223701 282.953455 \n",
       "L 207.576206 284.693834 \n",
       "L 217.928711 286.271898 \n",
       "L 228.281215 287.709343 \n",
       "L 238.63372 289.024162 \n",
       "L 248.986224 290.231405 \n",
       "L 259.338729 291.343755 \n",
       "L 269.691234 292.371979 \n",
       "L 280.043738 293.325271 \n",
       "L 290.396243 294.211534 \n",
       "L 300.748748 295.037599 \n",
       "L 311.101252 295.809396 \n",
       "L 321.453757 296.532104 \n",
       "L 331.806262 297.210262 \n",
       "L 342.158766 297.847865 \n",
       "L 352.511271 298.448446 \n",
       "L 362.863776 299.015138 \n",
       "L 373.21628 299.550732 \n",
       "L 383.568785 300.057718 \n",
       "L 393.921289 300.538329 \n",
       "L 404.273794 300.994571 \n",
       "L 414.626299 301.428252 \n",
       "L 424.978803 301.841004 \n",
       "L 435.331308 302.234307 \n",
       "L 445.683813 302.609505 \n",
       "L 456.036317 302.967818 \n",
       "L 466.388822 303.310362 \n",
       "L 476.741327 303.638156 \n",
       "L 487.093831 303.952131 \n",
       "L 497.446336 304.253144 \n",
       "L 507.79884 304.541982 \n",
       "L 518.151345 304.819367 \n",
       "L 528.50385 305.085969 \n",
       "L 538.856354 305.342404 \n",
       "L 549.208859 305.589242 \n",
       "L 559.561364 305.827013 \n",
       "\" style=\"fill:none;stroke:#55a868;stroke-dasharray:6.475,2.8;stroke-dashoffset:0;stroke-width:1.75;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_29\">\n",
       "    <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 52.288636 106.742338 \n",
       "L 62.641141 139.606646 \n",
       "L 72.993646 163.641737 \n",
       "L 83.34615 181.984306 \n",
       "L 93.698655 196.442567 \n",
       "L 104.05116 208.132224 \n",
       "L 114.403664 217.779029 \n",
       "L 124.756169 225.875455 \n",
       "L 135.108673 232.767453 \n",
       "L 145.461178 238.705175 \n",
       "L 155.813683 243.873983 \n",
       "L 166.166187 248.414152 \n",
       "L 176.518692 252.433793 \n",
       "L 186.871197 256.017568 \n",
       "L 197.223701 259.232727 \n",
       "L 207.576206 262.13336 \n",
       "L 217.928711 264.763467 \n",
       "L 228.281215 267.159208 \n",
       "L 238.63372 269.350573 \n",
       "L 248.986224 271.362645 \n",
       "L 259.338729 273.216562 \n",
       "L 269.691234 274.930267 \n",
       "L 280.043738 276.519087 \n",
       "L 290.396243 277.996193 \n",
       "L 300.748748 279.372967 \n",
       "L 311.101252 280.659297 \n",
       "L 321.453757 281.86381 \n",
       "L 331.806262 282.994072 \n",
       "L 342.158766 284.056744 \n",
       "L 352.511271 285.057713 \n",
       "L 362.863776 286.0022 \n",
       "L 373.21628 286.894856 \n",
       "L 383.568785 287.739833 \n",
       "L 393.921289 288.540851 \n",
       "L 404.273794 289.301255 \n",
       "L 414.626299 290.024056 \n",
       "L 424.978803 290.711977 \n",
       "L 435.331308 291.367482 \n",
       "L 445.683813 291.992811 \n",
       "L 456.036317 292.59 \n",
       "L 466.388822 293.160907 \n",
       "L 476.741327 293.707229 \n",
       "L 487.093831 294.230522 \n",
       "L 497.446336 294.73221 \n",
       "L 507.79884 295.213606 \n",
       "L 518.151345 295.675915 \n",
       "L 528.50385 296.120251 \n",
       "L 538.856354 296.547643 \n",
       "L 549.208859 296.95904 \n",
       "L 559.561364 297.355325 \n",
       "\" style=\"fill:none;stroke:#c44e52;stroke-linecap:round;stroke-width:1.75;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_30\">\n",
       "    <path clip-path=\"url(#pf6001bc1d4)\" d=\"M 52.288636 22.025455 \n",
       "L 62.641141 68.035486 \n",
       "L 72.993646 101.684613 \n",
       "L 83.34615 127.364211 \n",
       "L 93.698655 147.605775 \n",
       "L 104.05116 163.971296 \n",
       "L 114.403664 177.476823 \n",
       "L 124.756169 188.811818 \n",
       "L 135.108673 198.460616 \n",
       "L 145.461178 206.773427 \n",
       "L 155.813683 214.009758 \n",
       "L 166.166187 220.365995 \n",
       "L 176.518692 225.993492 \n",
       "L 186.871197 231.010778 \n",
       "L 197.223701 235.512 \n",
       "L 207.576206 239.572885 \n",
       "L 217.928711 243.255035 \n",
       "L 228.281215 246.609073 \n",
       "L 238.63372 249.676984 \n",
       "L 248.986224 252.493884 \n",
       "L 259.338729 255.089369 \n",
       "L 269.691234 257.488556 \n",
       "L 280.043738 259.712904 \n",
       "L 290.396243 261.780852 \n",
       "L 300.748748 263.708336 \n",
       "L 311.101252 265.509197 \n",
       "L 321.453757 267.195516 \n",
       "L 331.806262 268.777883 \n",
       "L 342.158766 270.265624 \n",
       "L 352.511271 271.666979 \n",
       "L 362.863776 272.989262 \n",
       "L 373.21628 274.23898 \n",
       "L 383.568785 275.421948 \n",
       "L 393.921289 276.543374 \n",
       "L 404.273794 277.607939 \n",
       "L 414.626299 278.61986 \n",
       "L 424.978803 279.582949 \n",
       "L 435.331308 280.500657 \n",
       "L 445.683813 281.376117 \n",
       "L 456.036317 282.212182 \n",
       "L 466.388822 283.011451 \n",
       "L 476.741327 283.776303 \n",
       "L 487.093831 284.508912 \n",
       "L 497.446336 285.211276 \n",
       "L 507.79884 285.88523 \n",
       "L 518.151345 286.532463 \n",
       "L 528.50385 287.154534 \n",
       "L 538.856354 287.752881 \n",
       "L 549.208859 288.328838 \n",
       "L 559.561364 288.883636 \n",
       "\" style=\"fill:none;stroke:#8172b2;stroke-dasharray:11.2,2.8,1.75,2.8;stroke-dashoffset:0;stroke-width:1.75;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_31\">\n",
       "    <defs>\n",
       "     <path d=\"M 0 3.5 \n",
       "C 0.928211 3.5 1.81853 3.131218 2.474874 2.474874 \n",
       "C 3.131218 1.81853 3.5 0.928211 3.5 0 \n",
       "C 3.5 -0.928211 3.131218 -1.81853 2.474874 -2.474874 \n",
       "C 1.81853 -3.131218 0.928211 -3.5 0 -3.5 \n",
       "C -0.928211 -3.5 -1.81853 -3.131218 -2.474874 -2.474874 \n",
       "C -3.131218 -1.81853 -3.5 -0.928211 -3.5 0 \n",
       "C -3.5 0.928211 -3.131218 1.81853 -2.474874 2.474874 \n",
       "C -1.81853 3.131218 -0.928211 3.5 0 3.5 \n",
       "z\n",
       "\" id=\"ma42173decc\"/>\n",
       "    </defs>\n",
       "    <g clip-path=\"url(#pf6001bc1d4)\">\n",
       "     <use style=\"fill:#ff0000;\" x=\"277.743182\" xlink:href=\"#ma42173decc\" y=\"276.176104\"/>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 26.925 333.36 \n",
       "L 26.925 7.2 \n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 584.925 333.36 \n",
       "L 584.925 7.2 \n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path d=\"M 26.925 333.36 \n",
       "L 584.925 333.36 \n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path d=\"M 26.925 7.2 \n",
       "L 584.925 7.2 \n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"legend_1\">\n",
       "    <g id=\"line2d_32\">\n",
       "     <path d=\"M 457.553125 20.298438 \n",
       "L 477.553125 20.298438 \n",
       "\" style=\"fill:none;stroke:#4c72b0;stroke-linecap:round;stroke-width:3;\"/>\n",
       "    </g>\n",
       "    <g id=\"line2d_33\"/>\n",
       "    <g id=\"text_14\">\n",
       "     <!-- budget constraint -->\n",
       "     <g style=\"fill:#262626;\" transform=\"translate(485.553125 23.798438)scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path d=\"M 738 331 \n",
       "L 738 4531 \n",
       "L 184 4531 \n",
       "L 184 4863 \n",
       "L 1313 4863 \n",
       "L 1313 2803 \n",
       "Q 1481 3116 1742 3264 \n",
       "Q 2003 3413 2388 3413 \n",
       "Q 3000 3413 3387 2928 \n",
       "Q 3775 2444 3775 1663 \n",
       "Q 3775 881 3387 395 \n",
       "Q 3000 -91 2388 -91 \n",
       "Q 2003 -91 1742 57 \n",
       "Q 1481 206 1313 519 \n",
       "L 1313 0 \n",
       "L 184 0 \n",
       "L 184 331 \n",
       "L 738 331 \n",
       "z\n",
       "M 1313 1497 \n",
       "Q 1313 897 1542 583 \n",
       "Q 1772 269 2209 269 \n",
       "Q 2650 269 2876 622 \n",
       "Q 3103 975 3103 1663 \n",
       "Q 3103 2353 2876 2703 \n",
       "Q 2650 3053 2209 3053 \n",
       "Q 1772 3053 1542 2737 \n",
       "Q 1313 2422 1313 1825 \n",
       "L 1313 1497 \n",
       "z\n",
       "\" id=\"DejaVuSerif-62\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 2266 3322 \n",
       "L 3341 3322 \n",
       "L 3341 331 \n",
       "L 3884 331 \n",
       "L 3884 0 \n",
       "L 2766 0 \n",
       "L 2766 588 \n",
       "Q 2606 256 2353 82 \n",
       "Q 2100 -91 1766 -91 \n",
       "Q 1213 -91 952 223 \n",
       "Q 691 538 691 1209 \n",
       "L 691 2988 \n",
       "L 172 2988 \n",
       "L 172 3322 \n",
       "L 1269 3322 \n",
       "L 1269 1388 \n",
       "Q 1269 781 1417 556 \n",
       "Q 1566 331 1947 331 \n",
       "Q 2347 331 2556 625 \n",
       "Q 2766 919 2766 1478 \n",
       "L 2766 2988 \n",
       "L 2266 2988 \n",
       "L 2266 3322 \n",
       "z\n",
       "\" id=\"DejaVuSerif-75\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 3359 331 \n",
       "L 3909 331 \n",
       "L 3909 0 \n",
       "L 2784 0 \n",
       "L 2784 519 \n",
       "Q 2616 206 2355 57 \n",
       "Q 2094 -91 1709 -91 \n",
       "Q 1097 -91 708 395 \n",
       "Q 319 881 319 1663 \n",
       "Q 319 2444 706 2928 \n",
       "Q 1094 3413 1709 3413 \n",
       "Q 2094 3413 2355 3264 \n",
       "Q 2616 3116 2784 2803 \n",
       "L 2784 4531 \n",
       "L 2241 4531 \n",
       "L 2241 4863 \n",
       "L 3359 4863 \n",
       "L 3359 331 \n",
       "z\n",
       "M 2784 1497 \n",
       "L 2784 1825 \n",
       "Q 2784 2422 2554 2737 \n",
       "Q 2325 3053 1888 3053 \n",
       "Q 1444 3053 1217 2703 \n",
       "Q 991 2353 991 1663 \n",
       "Q 991 975 1217 622 \n",
       "Q 1444 269 1888 269 \n",
       "Q 2325 269 2554 583 \n",
       "Q 2784 897 2784 1497 \n",
       "z\n",
       "\" id=\"DejaVuSerif-64\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 3359 2988 \n",
       "L 3359 72 \n",
       "Q 3359 -644 2965 -1033 \n",
       "Q 2572 -1422 1844 -1422 \n",
       "Q 1516 -1422 1216 -1362 \n",
       "Q 916 -1303 641 -1184 \n",
       "L 641 -488 \n",
       "L 941 -488 \n",
       "Q 997 -813 1206 -963 \n",
       "Q 1416 -1113 1806 -1113 \n",
       "Q 2313 -1113 2548 -827 \n",
       "Q 2784 -541 2784 72 \n",
       "L 2784 519 \n",
       "Q 2616 206 2355 57 \n",
       "Q 2094 -91 1709 -91 \n",
       "Q 1097 -91 708 395 \n",
       "Q 319 881 319 1663 \n",
       "Q 319 2444 706 2928 \n",
       "Q 1094 3413 1709 3413 \n",
       "Q 2094 3413 2355 3264 \n",
       "Q 2616 3116 2784 2803 \n",
       "L 2784 3322 \n",
       "L 3909 3322 \n",
       "L 3909 2988 \n",
       "L 3359 2988 \n",
       "z\n",
       "M 2784 1825 \n",
       "Q 2784 2422 2554 2737 \n",
       "Q 2325 3053 1888 3053 \n",
       "Q 1444 3053 1217 2703 \n",
       "Q 991 2353 991 1663 \n",
       "Q 991 975 1217 622 \n",
       "Q 1444 269 1888 269 \n",
       "Q 2325 269 2554 583 \n",
       "Q 2784 897 2784 1497 \n",
       "L 2784 1825 \n",
       "z\n",
       "\" id=\"DejaVuSerif-67\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 3469 1600 \n",
       "L 991 1600 \n",
       "L 991 1575 \n",
       "Q 991 903 1244 561 \n",
       "Q 1497 219 1991 219 \n",
       "Q 2369 219 2611 417 \n",
       "Q 2853 616 2950 1006 \n",
       "L 3413 1006 \n",
       "Q 3275 459 2904 184 \n",
       "Q 2534 -91 1931 -91 \n",
       "Q 1203 -91 761 389 \n",
       "Q 319 869 319 1663 \n",
       "Q 319 2450 753 2931 \n",
       "Q 1188 3413 1894 3413 \n",
       "Q 2647 3413 3050 2948 \n",
       "Q 3453 2484 3469 1600 \n",
       "z\n",
       "M 2791 1931 \n",
       "Q 2772 2513 2545 2808 \n",
       "Q 2319 3103 1894 3103 \n",
       "Q 1497 3103 1269 2806 \n",
       "Q 1041 2509 991 1931 \n",
       "L 2791 1931 \n",
       "z\n",
       "\" id=\"DejaVuSerif-65\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 691 2988 \n",
       "L 184 2988 \n",
       "L 184 3322 \n",
       "L 691 3322 \n",
       "L 691 4353 \n",
       "L 1269 4353 \n",
       "L 1269 3322 \n",
       "L 2350 3322 \n",
       "L 2350 2988 \n",
       "L 1269 2988 \n",
       "L 1269 878 \n",
       "Q 1269 456 1350 337 \n",
       "Q 1431 219 1650 219 \n",
       "Q 1875 219 1978 351 \n",
       "Q 2081 484 2088 781 \n",
       "L 2522 781 \n",
       "Q 2497 328 2275 118 \n",
       "Q 2053 -91 1600 -91 \n",
       "Q 1103 -91 897 129 \n",
       "Q 691 350 691 878 \n",
       "L 691 2988 \n",
       "z\n",
       "\" id=\"DejaVuSerif-74\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSerif-20\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 3291 997 \n",
       "Q 3169 466 2822 187 \n",
       "Q 2475 -91 1925 -91 \n",
       "Q 1200 -91 759 389 \n",
       "Q 319 869 319 1663 \n",
       "Q 319 2459 759 2936 \n",
       "Q 1200 3413 1925 3413 \n",
       "Q 2241 3413 2553 3339 \n",
       "Q 2866 3266 3181 3116 \n",
       "L 3181 2266 \n",
       "L 2847 2266 \n",
       "Q 2781 2703 2561 2903 \n",
       "Q 2341 3103 1931 3103 \n",
       "Q 1466 3103 1228 2742 \n",
       "Q 991 2381 991 1663 \n",
       "Q 991 944 1227 581 \n",
       "Q 1463 219 1931 219 \n",
       "Q 2303 219 2525 412 \n",
       "Q 2747 606 2828 997 \n",
       "L 3291 997 \n",
       "z\n",
       "\" id=\"DejaVuSerif-63\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 1925 219 \n",
       "Q 2388 219 2623 584 \n",
       "Q 2859 950 2859 1663 \n",
       "Q 2859 2375 2623 2739 \n",
       "Q 2388 3103 1925 3103 \n",
       "Q 1463 3103 1227 2739 \n",
       "Q 991 2375 991 1663 \n",
       "Q 991 950 1228 584 \n",
       "Q 1466 219 1925 219 \n",
       "z\n",
       "M 1925 -91 \n",
       "Q 1200 -91 759 389 \n",
       "Q 319 869 319 1663 \n",
       "Q 319 2456 758 2934 \n",
       "Q 1197 3413 1925 3413 \n",
       "Q 2653 3413 3092 2934 \n",
       "Q 3531 2456 3531 1663 \n",
       "Q 3531 869 3092 389 \n",
       "Q 2653 -91 1925 -91 \n",
       "z\n",
       "\" id=\"DejaVuSerif-6f\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 263 0 \n",
       "L 263 331 \n",
       "L 781 331 \n",
       "L 781 2988 \n",
       "L 231 2988 \n",
       "L 231 3322 \n",
       "L 1356 3322 \n",
       "L 1356 2731 \n",
       "Q 1516 3069 1770 3241 \n",
       "Q 2025 3413 2363 3413 \n",
       "Q 2913 3413 3172 3097 \n",
       "Q 3431 2781 3431 2113 \n",
       "L 3431 331 \n",
       "L 3944 331 \n",
       "L 3944 0 \n",
       "L 2356 0 \n",
       "L 2356 331 \n",
       "L 2853 331 \n",
       "L 2853 1931 \n",
       "Q 2853 2541 2703 2767 \n",
       "Q 2553 2994 2175 2994 \n",
       "Q 1775 2994 1565 2701 \n",
       "Q 1356 2409 1356 1850 \n",
       "L 1356 331 \n",
       "L 1856 331 \n",
       "L 1856 0 \n",
       "L 263 0 \n",
       "z\n",
       "\" id=\"DejaVuSerif-6e\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 359 184 \n",
       "L 359 959 \n",
       "L 691 959 \n",
       "Q 703 588 923 403 \n",
       "Q 1144 219 1575 219 \n",
       "Q 1963 219 2166 364 \n",
       "Q 2369 509 2369 788 \n",
       "Q 2369 1006 2220 1140 \n",
       "Q 2072 1275 1594 1428 \n",
       "L 1178 1569 \n",
       "Q 750 1706 558 1912 \n",
       "Q 366 2119 366 2438 \n",
       "Q 366 2894 700 3153 \n",
       "Q 1034 3413 1625 3413 \n",
       "Q 1888 3413 2178 3344 \n",
       "Q 2469 3275 2778 3144 \n",
       "L 2778 2419 \n",
       "L 2447 2419 \n",
       "Q 2434 2741 2221 2922 \n",
       "Q 2009 3103 1644 3103 \n",
       "Q 1281 3103 1095 2975 \n",
       "Q 909 2847 909 2591 \n",
       "Q 909 2381 1050 2254 \n",
       "Q 1191 2128 1613 1997 \n",
       "L 2069 1856 \n",
       "Q 2541 1709 2748 1489 \n",
       "Q 2956 1269 2956 922 \n",
       "Q 2956 450 2595 179 \n",
       "Q 2234 -91 1600 -91 \n",
       "Q 1278 -91 972 -22 \n",
       "Q 666 47 359 184 \n",
       "z\n",
       "\" id=\"DejaVuSerif-73\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 3059 3328 \n",
       "L 3059 2497 \n",
       "L 2728 2497 \n",
       "Q 2713 2744 2591 2866 \n",
       "Q 2469 2988 2234 2988 \n",
       "Q 1809 2988 1582 2694 \n",
       "Q 1356 2400 1356 1850 \n",
       "L 1356 331 \n",
       "L 2022 331 \n",
       "L 2022 0 \n",
       "L 263 0 \n",
       "L 263 331 \n",
       "L 781 331 \n",
       "L 781 2994 \n",
       "L 231 2994 \n",
       "L 231 3322 \n",
       "L 1356 3322 \n",
       "L 1356 2731 \n",
       "Q 1525 3078 1790 3245 \n",
       "Q 2056 3413 2438 3413 \n",
       "Q 2578 3413 2733 3391 \n",
       "Q 2888 3369 3059 3328 \n",
       "z\n",
       "\" id=\"DejaVuSerif-72\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 2547 1044 \n",
       "L 2547 1747 \n",
       "L 1806 1747 \n",
       "Q 1378 1747 1168 1562 \n",
       "Q 959 1378 959 997 \n",
       "Q 959 650 1171 447 \n",
       "Q 1384 244 1747 244 \n",
       "Q 2106 244 2326 466 \n",
       "Q 2547 688 2547 1044 \n",
       "z\n",
       "M 3122 2075 \n",
       "L 3122 331 \n",
       "L 3634 331 \n",
       "L 3634 0 \n",
       "L 2547 0 \n",
       "L 2547 359 \n",
       "Q 2356 128 2106 18 \n",
       "Q 1856 -91 1522 -91 \n",
       "Q 969 -91 644 203 \n",
       "Q 319 497 319 997 \n",
       "Q 319 1513 691 1797 \n",
       "Q 1063 2081 1741 2081 \n",
       "L 2547 2081 \n",
       "L 2547 2309 \n",
       "Q 2547 2688 2317 2895 \n",
       "Q 2088 3103 1672 3103 \n",
       "Q 1328 3103 1125 2947 \n",
       "Q 922 2791 872 2484 \n",
       "L 575 2484 \n",
       "L 575 3156 \n",
       "Q 875 3284 1158 3348 \n",
       "Q 1441 3413 1709 3413 \n",
       "Q 2400 3413 2761 3070 \n",
       "Q 3122 2728 3122 2075 \n",
       "z\n",
       "\" id=\"DejaVuSerif-61\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 622 4353 \n",
       "Q 622 4497 726 4603 \n",
       "Q 831 4709 978 4709 \n",
       "Q 1122 4709 1226 4603 \n",
       "Q 1331 4497 1331 4353 \n",
       "Q 1331 4206 1228 4103 \n",
       "Q 1125 4000 978 4000 \n",
       "Q 831 4000 726 4103 \n",
       "Q 622 4206 622 4353 \n",
       "z\n",
       "M 1356 331 \n",
       "L 1900 331 \n",
       "L 1900 0 \n",
       "L 231 0 \n",
       "L 231 331 \n",
       "L 781 331 \n",
       "L 781 2988 \n",
       "L 231 2988 \n",
       "L 231 3322 \n",
       "L 1356 3322 \n",
       "L 1356 331 \n",
       "z\n",
       "\" id=\"DejaVuSerif-69\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#DejaVuSerif-62\"/>\n",
       "      <use x=\"64.013672\" xlink:href=\"#DejaVuSerif-75\"/>\n",
       "      <use x=\"128.417969\" xlink:href=\"#DejaVuSerif-64\"/>\n",
       "      <use x=\"192.431641\" xlink:href=\"#DejaVuSerif-67\"/>\n",
       "      <use x=\"256.445312\" xlink:href=\"#DejaVuSerif-65\"/>\n",
       "      <use x=\"315.625\" xlink:href=\"#DejaVuSerif-74\"/>\n",
       "      <use x=\"355.810547\" xlink:href=\"#DejaVuSerif-20\"/>\n",
       "      <use x=\"387.597656\" xlink:href=\"#DejaVuSerif-63\"/>\n",
       "      <use x=\"443.603516\" xlink:href=\"#DejaVuSerif-6f\"/>\n",
       "      <use x=\"503.808594\" xlink:href=\"#DejaVuSerif-6e\"/>\n",
       "      <use x=\"568.212891\" xlink:href=\"#DejaVuSerif-73\"/>\n",
       "      <use x=\"619.53125\" xlink:href=\"#DejaVuSerif-74\"/>\n",
       "      <use x=\"659.716797\" xlink:href=\"#DejaVuSerif-72\"/>\n",
       "      <use x=\"707.519531\" xlink:href=\"#DejaVuSerif-61\"/>\n",
       "      <use x=\"767.138672\" xlink:href=\"#DejaVuSerif-69\"/>\n",
       "      <use x=\"799.121094\" xlink:href=\"#DejaVuSerif-6e\"/>\n",
       "      <use x=\"863.525391\" xlink:href=\"#DejaVuSerif-74\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"line2d_34\">\n",
       "     <path d=\"M 457.553125 35.11875 \n",
       "L 477.553125 35.11875 \n",
       "\" style=\"fill:none;stroke:#55a868;stroke-dasharray:6.475,2.8;stroke-dashoffset:0;stroke-width:1.75;\"/>\n",
       "    </g>\n",
       "    <g id=\"line2d_35\"/>\n",
       "    <g id=\"text_15\">\n",
       "     <!-- $u=15$ -->\n",
       "     <g style=\"fill:#262626;\" transform=\"translate(485.553125 38.61875)scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path d=\"M 428 1388 \n",
       "L 838 3500 \n",
       "L 1416 3500 \n",
       "L 1006 1409 \n",
       "Q 975 1256 961 1147 \n",
       "Q 947 1038 947 966 \n",
       "Q 947 700 1109 554 \n",
       "Q 1272 409 1569 409 \n",
       "Q 2031 409 2368 721 \n",
       "Q 2706 1034 2809 1563 \n",
       "L 3194 3500 \n",
       "L 3769 3500 \n",
       "L 3091 0 \n",
       "L 2516 0 \n",
       "L 2631 550 \n",
       "Q 2388 244 2052 76 \n",
       "Q 1716 -91 1338 -91 \n",
       "Q 878 -91 622 161 \n",
       "Q 366 413 366 863 \n",
       "Q 366 956 381 1097 \n",
       "Q 397 1238 428 1388 \n",
       "z\n",
       "\" id=\"DejaVuSans-Oblique-75\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 678 2906 \n",
       "L 4684 2906 \n",
       "L 4684 2381 \n",
       "L 678 2381 \n",
       "L 678 2906 \n",
       "z\n",
       "M 678 1631 \n",
       "L 4684 1631 \n",
       "L 4684 1100 \n",
       "L 678 1100 \n",
       "L 678 1631 \n",
       "z\n",
       "\" id=\"DejaVuSans-3d\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 794 531 \n",
       "L 1825 531 \n",
       "L 1825 4091 \n",
       "L 703 3866 \n",
       "L 703 4441 \n",
       "L 1819 4666 \n",
       "L 2450 4666 \n",
       "L 2450 531 \n",
       "L 3481 531 \n",
       "L 3481 0 \n",
       "L 794 0 \n",
       "L 794 531 \n",
       "z\n",
       "\" id=\"DejaVuSans-31\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 691 4666 \n",
       "L 3169 4666 \n",
       "L 3169 4134 \n",
       "L 1269 4134 \n",
       "L 1269 2991 \n",
       "Q 1406 3038 1543 3061 \n",
       "Q 1681 3084 1819 3084 \n",
       "Q 2600 3084 3056 2656 \n",
       "Q 3513 2228 3513 1497 \n",
       "Q 3513 744 3044 326 \n",
       "Q 2575 -91 1722 -91 \n",
       "Q 1428 -91 1123 -41 \n",
       "Q 819 9 494 109 \n",
       "L 494 744 \n",
       "Q 775 591 1075 516 \n",
       "Q 1375 441 1709 441 \n",
       "Q 2250 441 2565 725 \n",
       "Q 2881 1009 2881 1497 \n",
       "Q 2881 1984 2565 2268 \n",
       "Q 2250 2553 1709 2553 \n",
       "Q 1456 2553 1204 2497 \n",
       "Q 953 2441 691 2322 \n",
       "L 691 4666 \n",
       "z\n",
       "\" id=\"DejaVuSans-35\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use transform=\"translate(0 0.09375)\" xlink:href=\"#DejaVuSans-Oblique-75\"/>\n",
       "      <use transform=\"translate(82.861328 0.09375)\" xlink:href=\"#DejaVuSans-3d\"/>\n",
       "      <use transform=\"translate(186.132812 0.09375)\" xlink:href=\"#DejaVuSans-31\"/>\n",
       "      <use transform=\"translate(249.755859 0.09375)\" xlink:href=\"#DejaVuSans-35\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"line2d_36\">\n",
       "     <path d=\"M 457.553125 49.796875 \n",
       "L 477.553125 49.796875 \n",
       "\" style=\"fill:none;stroke:#c44e52;stroke-linecap:round;stroke-width:1.75;\"/>\n",
       "    </g>\n",
       "    <g id=\"line2d_37\"/>\n",
       "    <g id=\"text_16\">\n",
       "     <!-- $u=25$ -->\n",
       "     <g style=\"fill:#262626;\" transform=\"translate(485.553125 53.296875)scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path d=\"M 1228 531 \n",
       "L 3431 531 \n",
       "L 3431 0 \n",
       "L 469 0 \n",
       "L 469 531 \n",
       "Q 828 903 1448 1529 \n",
       "Q 2069 2156 2228 2338 \n",
       "Q 2531 2678 2651 2914 \n",
       "Q 2772 3150 2772 3378 \n",
       "Q 2772 3750 2511 3984 \n",
       "Q 2250 4219 1831 4219 \n",
       "Q 1534 4219 1204 4116 \n",
       "Q 875 4013 500 3803 \n",
       "L 500 4441 \n",
       "Q 881 4594 1212 4672 \n",
       "Q 1544 4750 1819 4750 \n",
       "Q 2544 4750 2975 4387 \n",
       "Q 3406 4025 3406 3419 \n",
       "Q 3406 3131 3298 2873 \n",
       "Q 3191 2616 2906 2266 \n",
       "Q 2828 2175 2409 1742 \n",
       "Q 1991 1309 1228 531 \n",
       "z\n",
       "\" id=\"DejaVuSans-32\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use transform=\"translate(0 0.78125)\" xlink:href=\"#DejaVuSans-Oblique-75\"/>\n",
       "      <use transform=\"translate(82.861328 0.78125)\" xlink:href=\"#DejaVuSans-3d\"/>\n",
       "      <use transform=\"translate(186.132812 0.78125)\" xlink:href=\"#DejaVuSans-32\"/>\n",
       "      <use transform=\"translate(249.755859 0.78125)\" xlink:href=\"#DejaVuSans-35\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"line2d_38\">\n",
       "     <path d=\"M 457.553125 64.475 \n",
       "L 477.553125 64.475 \n",
       "\" style=\"fill:none;stroke:#8172b2;stroke-dasharray:11.2,2.8,1.75,2.8;stroke-dashoffset:0;stroke-width:1.75;\"/>\n",
       "    </g>\n",
       "    <g id=\"line2d_39\"/>\n",
       "    <g id=\"text_17\">\n",
       "     <!-- $u=35$ -->\n",
       "     <g style=\"fill:#262626;\" transform=\"translate(485.553125 67.975)scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path d=\"M 2597 2516 \n",
       "Q 3050 2419 3304 2112 \n",
       "Q 3559 1806 3559 1356 \n",
       "Q 3559 666 3084 287 \n",
       "Q 2609 -91 1734 -91 \n",
       "Q 1441 -91 1130 -33 \n",
       "Q 819 25 488 141 \n",
       "L 488 750 \n",
       "Q 750 597 1062 519 \n",
       "Q 1375 441 1716 441 \n",
       "Q 2309 441 2620 675 \n",
       "Q 2931 909 2931 1356 \n",
       "Q 2931 1769 2642 2001 \n",
       "Q 2353 2234 1838 2234 \n",
       "L 1294 2234 \n",
       "L 1294 2753 \n",
       "L 1863 2753 \n",
       "Q 2328 2753 2575 2939 \n",
       "Q 2822 3125 2822 3475 \n",
       "Q 2822 3834 2567 4026 \n",
       "Q 2313 4219 1838 4219 \n",
       "Q 1578 4219 1281 4162 \n",
       "Q 984 4106 628 3988 \n",
       "L 628 4550 \n",
       "Q 988 4650 1302 4700 \n",
       "Q 1616 4750 1894 4750 \n",
       "Q 2613 4750 3031 4423 \n",
       "Q 3450 4097 3450 3541 \n",
       "Q 3450 3153 3228 2886 \n",
       "Q 3006 2619 2597 2516 \n",
       "z\n",
       "\" id=\"DejaVuSans-33\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use transform=\"translate(0 0.78125)\" xlink:href=\"#DejaVuSans-Oblique-75\"/>\n",
       "      <use transform=\"translate(82.861328 0.78125)\" xlink:href=\"#DejaVuSans-3d\"/>\n",
       "      <use transform=\"translate(186.132812 0.78125)\" xlink:href=\"#DejaVuSans-33\"/>\n",
       "      <use transform=\"translate(249.755859 0.78125)\" xlink:href=\"#DejaVuSans-35\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"line2d_40\"/>\n",
       "    <g id=\"line2d_41\">\n",
       "     <g>\n",
       "      <use style=\"fill:#ff0000;\" x=\"467.553125\" xlink:href=\"#ma42173decc\" y=\"79.153125\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"text_18\">\n",
       "     <!-- $c=(5, 5)$ -->\n",
       "     <g style=\"fill:#262626;\" transform=\"translate(485.553125 82.653125)scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path d=\"M 3431 3366 \n",
       "L 3316 2797 \n",
       "Q 3109 2947 2876 3022 \n",
       "Q 2644 3097 2394 3097 \n",
       "Q 2119 3097 1870 3000 \n",
       "Q 1622 2903 1453 2725 \n",
       "Q 1184 2453 1037 2087 \n",
       "Q 891 1722 891 1331 \n",
       "Q 891 859 1127 628 \n",
       "Q 1363 397 1844 397 \n",
       "Q 2081 397 2348 469 \n",
       "Q 2616 541 2906 684 \n",
       "L 2797 116 \n",
       "Q 2547 13 2283 -39 \n",
       "Q 2019 -91 1741 -91 \n",
       "Q 1044 -91 669 257 \n",
       "Q 294 606 294 1253 \n",
       "Q 294 1797 489 2255 \n",
       "Q 684 2713 1069 3078 \n",
       "Q 1331 3328 1684 3456 \n",
       "Q 2038 3584 2456 3584 \n",
       "Q 2700 3584 2940 3529 \n",
       "Q 3181 3475 3431 3366 \n",
       "z\n",
       "\" id=\"DejaVuSans-Oblique-63\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 1984 4856 \n",
       "Q 1566 4138 1362 3434 \n",
       "Q 1159 2731 1159 2009 \n",
       "Q 1159 1288 1364 580 \n",
       "Q 1569 -128 1984 -844 \n",
       "L 1484 -844 \n",
       "Q 1016 -109 783 600 \n",
       "Q 550 1309 550 2009 \n",
       "Q 550 2706 781 3412 \n",
       "Q 1013 4119 1484 4856 \n",
       "L 1984 4856 \n",
       "z\n",
       "\" id=\"DejaVuSans-28\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 750 794 \n",
       "L 1409 794 \n",
       "L 1409 256 \n",
       "L 897 -744 \n",
       "L 494 -744 \n",
       "L 750 256 \n",
       "L 750 794 \n",
       "z\n",
       "\" id=\"DejaVuSans-2c\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 513 4856 \n",
       "L 1013 4856 \n",
       "Q 1481 4119 1714 3412 \n",
       "Q 1947 2706 1947 2009 \n",
       "Q 1947 1309 1714 600 \n",
       "Q 1481 -109 1013 -844 \n",
       "L 513 -844 \n",
       "Q 928 -128 1133 580 \n",
       "Q 1338 1288 1338 2009 \n",
       "Q 1338 2731 1133 3434 \n",
       "Q 928 4138 513 4856 \n",
       "z\n",
       "\" id=\"DejaVuSans-29\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use transform=\"translate(0 0.125)\" xlink:href=\"#DejaVuSans-Oblique-63\"/>\n",
       "      <use transform=\"translate(74.462891 0.125)\" xlink:href=\"#DejaVuSans-3d\"/>\n",
       "      <use transform=\"translate(177.734375 0.125)\" xlink:href=\"#DejaVuSans-28\"/>\n",
       "      <use transform=\"translate(216.748047 0.125)\" xlink:href=\"#DejaVuSans-35\"/>\n",
       "      <use transform=\"translate(280.371094 0.125)\" xlink:href=\"#DejaVuSans-2c\"/>\n",
       "      <use transform=\"translate(331.640625 0.125)\" xlink:href=\"#DejaVuSans-35\"/>\n",
       "      <use transform=\"translate(395.263672 0.125)\" xlink:href=\"#DejaVuSans-29\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pf6001bc1d4\">\n",
       "   <rect height=\"326.16\" width=\"558\" x=\"26.925\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(10, 6))\n",
    "plt.plot(c0, c1(c0), label='budget constraint', lw=3.0)\n",
    "plt.plot(c0, iu(15, c0), '--', label='$u=15$')\n",
    "plt.plot(c0, iu(25, c0), label='$u=25$')\n",
    "plt.plot(c0, iu(35, c0), '-.', label='$u=35$')\n",
    "plt.plot(opt['x'][0], opt['x'][1], 'ro', label='$c=(5, 5)$')\n",
    "plt.legend(loc=0);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Logarithmic Function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.linspace(0.5, 10, 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.5    , 0.69388, 0.88776, 1.08163, 1.27551])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "u = np.log(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "u1 = 1 / x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "u2 = -1 / x ** 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg height=\"357.238125pt\" version=\"1.1\" viewBox=\"0 0 594.142187 357.238125\" width=\"594.142187pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       " <metadata>\n",
       "  <rdf:RDF xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
       "   <cc:Work>\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
       "    <dc:date>2021-10-19T11:02:08.801640</dc:date>\n",
       "    <dc:format>image/svg+xml</dc:format>\n",
       "    <dc:creator>\n",
       "     <cc:Agent>\n",
       "      <dc:title>Matplotlib v3.4.1, https://matplotlib.org/</dc:title>\n",
       "     </cc:Agent>\n",
       "    </dc:creator>\n",
       "   </cc:Work>\n",
       "  </rdf:RDF>\n",
       " </metadata>\n",
       " <defs>\n",
       "  <style type=\"text/css\">*{stroke-linecap:butt;stroke-linejoin:round;}</style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 357.238125 \n",
       "L 594.142187 357.238125 \n",
       "L 594.142187 0 \n",
       "L 0 0 \n",
       "z\n",
       "\" style=\"fill:#ffffff;\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path d=\"M 28.942188 333.36 \n",
       "L 586.942188 333.36 \n",
       "L 586.942188 7.2 \n",
       "L 28.942188 7.2 \n",
       "z\n",
       "\" style=\"fill:#eaeaf2;\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\">\n",
       "    <g id=\"xtick_1\">\n",
       "     <g id=\"line2d_1\">\n",
       "      <path clip-path=\"url(#pc82c52488d)\" d=\"M 134.401518 333.36 \n",
       "L 134.401518 7.2 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_2\"/>\n",
       "     <g id=\"text_1\">\n",
       "      <!-- 2 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(131.220268 347.958438)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path d=\"M 819 3553 \n",
       "L 469 3553 \n",
       "L 469 4384 \n",
       "Q 803 4563 1142 4656 \n",
       "Q 1481 4750 1806 4750 \n",
       "Q 2534 4750 2956 4397 \n",
       "Q 3378 4044 3378 3438 \n",
       "Q 3378 2753 2422 1800 \n",
       "Q 2347 1728 2309 1691 \n",
       "L 1131 513 \n",
       "L 3078 513 \n",
       "L 3078 1088 \n",
       "L 3444 1088 \n",
       "L 3444 0 \n",
       "L 434 0 \n",
       "L 434 341 \n",
       "L 1850 1753 \n",
       "Q 2319 2222 2519 2614 \n",
       "Q 2719 3006 2719 3438 \n",
       "Q 2719 3909 2473 4175 \n",
       "Q 2228 4441 1797 4441 \n",
       "Q 1350 4441 1106 4219 \n",
       "Q 863 3997 819 3553 \n",
       "z\n",
       "\" id=\"DejaVuSerif-32\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSerif-32\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_3\">\n",
       "      <path clip-path=\"url(#pc82c52488d)\" d=\"M 241.195776 333.36 \n",
       "L 241.195776 7.2 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_4\"/>\n",
       "     <g id=\"text_2\">\n",
       "      <!-- 4 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(238.014526 347.958438)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path d=\"M 2234 1581 \n",
       "L 2234 4063 \n",
       "L 641 1581 \n",
       "L 2234 1581 \n",
       "z\n",
       "M 3609 0 \n",
       "L 1484 0 \n",
       "L 1484 331 \n",
       "L 2234 331 \n",
       "L 2234 1247 \n",
       "L 197 1247 \n",
       "L 197 1588 \n",
       "L 2241 4750 \n",
       "L 2859 4750 \n",
       "L 2859 1581 \n",
       "L 3750 1581 \n",
       "L 3750 1247 \n",
       "L 2859 1247 \n",
       "L 2859 331 \n",
       "L 3609 331 \n",
       "L 3609 0 \n",
       "z\n",
       "\" id=\"DejaVuSerif-34\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSerif-34\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_5\">\n",
       "      <path clip-path=\"url(#pc82c52488d)\" d=\"M 347.990034 333.36 \n",
       "L 347.990034 7.2 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_6\"/>\n",
       "     <g id=\"text_3\">\n",
       "      <!-- 6 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(344.808784 347.958438)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path d=\"M 2094 219 \n",
       "Q 2534 219 2771 542 \n",
       "Q 3009 866 3009 1472 \n",
       "Q 3009 2078 2771 2401 \n",
       "Q 2534 2725 2094 2725 \n",
       "Q 1647 2725 1412 2412 \n",
       "Q 1178 2100 1178 1509 \n",
       "Q 1178 888 1415 553 \n",
       "Q 1653 219 2094 219 \n",
       "z\n",
       "M 1075 2569 \n",
       "Q 1288 2803 1556 2918 \n",
       "Q 1825 3034 2163 3034 \n",
       "Q 2859 3034 3264 2615 \n",
       "Q 3669 2197 3669 1472 \n",
       "Q 3669 763 3233 336 \n",
       "Q 2797 -91 2069 -91 \n",
       "Q 1278 -91 853 498 \n",
       "Q 428 1088 428 2181 \n",
       "Q 428 3406 931 4078 \n",
       "Q 1434 4750 2350 4750 \n",
       "Q 2597 4750 2869 4703 \n",
       "Q 3141 4656 3425 4563 \n",
       "L 3425 3794 \n",
       "L 3072 3794 \n",
       "Q 3034 4109 2831 4275 \n",
       "Q 2628 4441 2284 4441 \n",
       "Q 1678 4441 1381 3981 \n",
       "Q 1084 3522 1075 2569 \n",
       "z\n",
       "\" id=\"DejaVuSerif-36\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSerif-36\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_7\">\n",
       "      <path clip-path=\"url(#pc82c52488d)\" d=\"M 454.784293 333.36 \n",
       "L 454.784293 7.2 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_8\"/>\n",
       "     <g id=\"text_4\">\n",
       "      <!-- 8 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(451.603043 347.958438)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path d=\"M 2981 1275 \n",
       "Q 2981 1775 2732 2051 \n",
       "Q 2484 2328 2034 2328 \n",
       "Q 1584 2328 1336 2051 \n",
       "Q 1088 1775 1088 1275 \n",
       "Q 1088 772 1336 495 \n",
       "Q 1584 219 2034 219 \n",
       "Q 2484 219 2732 495 \n",
       "Q 2981 772 2981 1275 \n",
       "z\n",
       "M 2853 3541 \n",
       "Q 2853 3966 2637 4203 \n",
       "Q 2422 4441 2034 4441 \n",
       "Q 1650 4441 1433 4203 \n",
       "Q 1216 3966 1216 3541 \n",
       "Q 1216 3113 1433 2875 \n",
       "Q 1650 2638 2034 2638 \n",
       "Q 2422 2638 2637 2875 \n",
       "Q 2853 3113 2853 3541 \n",
       "z\n",
       "M 2516 2484 \n",
       "Q 3047 2413 3344 2092 \n",
       "Q 3641 1772 3641 1275 \n",
       "Q 3641 619 3225 264 \n",
       "Q 2809 -91 2034 -91 \n",
       "Q 1263 -91 845 264 \n",
       "Q 428 619 428 1275 \n",
       "Q 428 1772 725 2092 \n",
       "Q 1022 2413 1556 2484 \n",
       "Q 1084 2569 832 2842 \n",
       "Q 581 3116 581 3541 \n",
       "Q 581 4103 968 4426 \n",
       "Q 1356 4750 2034 4750 \n",
       "Q 2713 4750 3100 4426 \n",
       "Q 3488 4103 3488 3541 \n",
       "Q 3488 3116 3236 2842 \n",
       "Q 2984 2569 2516 2484 \n",
       "z\n",
       "\" id=\"DejaVuSerif-38\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSerif-38\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_9\">\n",
       "      <path clip-path=\"url(#pc82c52488d)\" d=\"M 561.578551 333.36 \n",
       "L 561.578551 7.2 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_10\"/>\n",
       "     <g id=\"text_5\">\n",
       "      <!-- 10 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(555.216051 347.958438)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path d=\"M 909 0 \n",
       "L 909 331 \n",
       "L 1722 331 \n",
       "L 1722 4213 \n",
       "L 781 3603 \n",
       "L 781 4013 \n",
       "L 1919 4750 \n",
       "L 2350 4750 \n",
       "L 2350 331 \n",
       "L 3163 331 \n",
       "L 3163 0 \n",
       "L 909 0 \n",
       "z\n",
       "\" id=\"DejaVuSerif-31\" transform=\"scale(0.015625)\"/>\n",
       "        <path d=\"M 2034 219 \n",
       "Q 2513 219 2750 744 \n",
       "Q 2988 1269 2988 2328 \n",
       "Q 2988 3391 2750 3916 \n",
       "Q 2513 4441 2034 4441 \n",
       "Q 1556 4441 1318 3916 \n",
       "Q 1081 3391 1081 2328 \n",
       "Q 1081 1269 1318 744 \n",
       "Q 1556 219 2034 219 \n",
       "z\n",
       "M 2034 -91 \n",
       "Q 1275 -91 848 546 \n",
       "Q 422 1184 422 2328 \n",
       "Q 422 3475 848 4112 \n",
       "Q 1275 4750 2034 4750 \n",
       "Q 2797 4750 3222 4112 \n",
       "Q 3647 3475 3647 2328 \n",
       "Q 3647 1184 3222 546 \n",
       "Q 2797 -91 2034 -91 \n",
       "z\n",
       "\" id=\"DejaVuSerif-30\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSerif-31\"/>\n",
       "       <use x=\"63.623047\" xlink:href=\"#DejaVuSerif-30\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_11\">\n",
       "      <path clip-path=\"url(#pc82c52488d)\" d=\"M 28.942188 318.534545 \n",
       "L 586.942188 318.534545 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_12\"/>\n",
       "     <g id=\"text_6\">\n",
       "      <!-- −4 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(7.2 322.333764)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path d=\"M 678 2259 \n",
       "L 4684 2259 \n",
       "L 4684 1753 \n",
       "L 678 1753 \n",
       "L 678 2259 \n",
       "z\n",
       "\" id=\"DejaVuSerif-2212\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSerif-2212\"/>\n",
       "       <use x=\"83.789062\" xlink:href=\"#DejaVuSerif-34\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_13\">\n",
       "      <path clip-path=\"url(#pc82c52488d)\" d=\"M 28.942188 271.488915 \n",
       "L 586.942188 271.488915 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_14\"/>\n",
       "     <g id=\"text_7\">\n",
       "      <!-- −3 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(7.2 275.288133)scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path d=\"M 622 4469 \n",
       "Q 988 4606 1323 4678 \n",
       "Q 1659 4750 1953 4750 \n",
       "Q 2638 4750 3022 4454 \n",
       "Q 3406 4159 3406 3634 \n",
       "Q 3406 3213 3140 2930 \n",
       "Q 2875 2647 2388 2547 \n",
       "Q 2963 2466 3280 2130 \n",
       "Q 3597 1794 3597 1259 \n",
       "Q 3597 606 3158 257 \n",
       "Q 2719 -91 1894 -91 \n",
       "Q 1528 -91 1179 -12 \n",
       "Q 831 66 488 225 \n",
       "L 488 1131 \n",
       "L 838 1131 \n",
       "Q 869 681 1141 450 \n",
       "Q 1413 219 1906 219 \n",
       "Q 2384 219 2661 495 \n",
       "Q 2938 772 2938 1253 \n",
       "Q 2938 1803 2653 2086 \n",
       "Q 2369 2369 1819 2369 \n",
       "L 1522 2369 \n",
       "L 1522 2688 \n",
       "L 1678 2688 \n",
       "Q 2225 2688 2498 2914 \n",
       "Q 2772 3141 2772 3597 \n",
       "Q 2772 4006 2547 4223 \n",
       "Q 2322 4441 1900 4441 \n",
       "Q 1478 4441 1245 4241 \n",
       "Q 1013 4041 972 3647 \n",
       "L 622 3647 \n",
       "L 622 4469 \n",
       "z\n",
       "\" id=\"DejaVuSerif-33\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSerif-2212\"/>\n",
       "       <use x=\"83.789062\" xlink:href=\"#DejaVuSerif-33\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_3\">\n",
       "     <g id=\"line2d_15\">\n",
       "      <path clip-path=\"url(#pc82c52488d)\" d=\"M 28.942188 224.443284 \n",
       "L 586.942188 224.443284 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_16\"/>\n",
       "     <g id=\"text_8\">\n",
       "      <!-- −2 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(7.2 228.242503)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSerif-2212\"/>\n",
       "       <use x=\"83.789062\" xlink:href=\"#DejaVuSerif-32\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_4\">\n",
       "     <g id=\"line2d_17\">\n",
       "      <path clip-path=\"url(#pc82c52488d)\" d=\"M 28.942188 177.397653 \n",
       "L 586.942188 177.397653 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_18\"/>\n",
       "     <g id=\"text_9\">\n",
       "      <!-- −1 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(7.2 181.196872)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSerif-2212\"/>\n",
       "       <use x=\"83.789062\" xlink:href=\"#DejaVuSerif-31\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_5\">\n",
       "     <g id=\"line2d_19\">\n",
       "      <path clip-path=\"url(#pc82c52488d)\" d=\"M 28.942188 130.352023 \n",
       "L 586.942188 130.352023 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_20\"/>\n",
       "     <g id=\"text_10\">\n",
       "      <!-- 0 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(15.579688 134.151241)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSerif-30\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_6\">\n",
       "     <g id=\"line2d_21\">\n",
       "      <path clip-path=\"url(#pc82c52488d)\" d=\"M 28.942188 83.306392 \n",
       "L 586.942188 83.306392 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_22\"/>\n",
       "     <g id=\"text_11\">\n",
       "      <!-- 1 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(15.579688 87.105611)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSerif-31\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_7\">\n",
       "     <g id=\"line2d_23\">\n",
       "      <path clip-path=\"url(#pc82c52488d)\" d=\"M 28.942188 36.260761 \n",
       "L 586.942188 36.260761 \n",
       "\" style=\"fill:none;stroke:#ffffff;stroke-linecap:round;\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_24\"/>\n",
       "     <g id=\"text_12\">\n",
       "      <!-- 2 -->\n",
       "      <g style=\"fill:#262626;\" transform=\"translate(15.579688 40.05998)scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSerif-32\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"line2d_25\">\n",
       "    <path clip-path=\"url(#pc82c52488d)\" d=\"M 54.305824 162.961569 \n",
       "L 64.658329 147.545308 \n",
       "L 75.010833 135.953245 \n",
       "L 85.363338 126.660276 \n",
       "L 95.715842 118.903644 \n",
       "L 106.068347 112.246708 \n",
       "L 116.420852 106.416018 \n",
       "L 126.773356 101.228933 \n",
       "L 137.125861 96.557385 \n",
       "L 147.478366 92.3081 \n",
       "L 157.83087 88.411027 \n",
       "L 168.183375 84.812223 \n",
       "L 178.53588 81.469259 \n",
       "L 188.888384 78.34816 \n",
       "L 199.240889 75.421301 \n",
       "L 209.593393 72.665916 \n",
       "L 219.945898 70.06302 \n",
       "L 230.298403 67.596615 \n",
       "L 240.650907 65.253098 \n",
       "L 251.003412 63.020801 \n",
       "L 261.355917 60.889646 \n",
       "L 271.708421 58.850861 \n",
       "L 282.060926 56.896773 \n",
       "L 292.413431 55.020623 \n",
       "L 302.765935 53.216432 \n",
       "L 313.11844 51.478884 \n",
       "L 323.470944 49.80323 \n",
       "L 333.823449 48.185211 \n",
       "L 344.175954 46.620996 \n",
       "L 354.528458 45.107119 \n",
       "L 364.880963 43.640443 \n",
       "L 375.233468 42.218111 \n",
       "L 385.585972 40.837523 \n",
       "L 395.938477 39.496296 \n",
       "L 406.290982 38.192249 \n",
       "L 416.643486 36.923376 \n",
       "L 426.995991 35.687829 \n",
       "L 437.348495 34.483902 \n",
       "L 447.701 33.310017 \n",
       "L 458.053505 32.164711 \n",
       "L 468.406009 31.046626 \n",
       "L 478.758514 29.954498 \n",
       "L 489.111019 28.887148 \n",
       "L 499.463523 27.843478 \n",
       "L 509.816028 26.822459 \n",
       "L 520.168533 25.823129 \n",
       "L 530.521037 24.844586 \n",
       "L 540.873542 23.885982 \n",
       "L 551.226046 22.946522 \n",
       "L 561.578551 22.025455 \n",
       "\" style=\"fill:none;stroke:#4c72b0;stroke-linecap:round;stroke-width:1.75;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_26\">\n",
       "    <path clip-path=\"url(#pc82c52488d)\" d=\"M 54.305824 36.260761 \n",
       "L 64.658329 62.550967 \n",
       "L 75.010833 77.358094 \n",
       "L 85.363338 86.857005 \n",
       "L 95.715842 93.468248 \n",
       "L 106.068347 98.334857 \n",
       "L 116.420852 102.066919 \n",
       "L 126.773356 105.01976 \n",
       "L 137.125861 107.414352 \n",
       "L 147.478366 109.395332 \n",
       "L 157.83087 111.061346 \n",
       "L 168.183375 112.481977 \n",
       "L 178.53588 113.70772 \n",
       "L 188.888384 114.776104 \n",
       "L 199.240889 115.715604 \n",
       "L 209.593393 116.548215 \n",
       "L 219.945898 117.291196 \n",
       "L 230.298403 117.958281 \n",
       "L 240.650907 118.560535 \n",
       "L 251.003412 119.106969 \n",
       "L 261.355917 119.605002 \n",
       "L 271.708421 120.060791 \n",
       "L 282.060926 120.479492 \n",
       "L 292.413431 120.865455 \n",
       "L 302.765935 121.222375 \n",
       "L 313.11844 121.553412 \n",
       "L 323.470944 121.861283 \n",
       "L 333.823449 122.148336 \n",
       "L 344.175954 122.416615 \n",
       "L 354.528458 122.667903 \n",
       "L 364.880963 122.903764 \n",
       "L 375.233468 123.125578 \n",
       "L 385.585972 123.334562 \n",
       "L 395.938477 123.531798 \n",
       "L 406.290982 123.71825 \n",
       "L 416.643486 123.894779 \n",
       "L 426.995991 124.062157 \n",
       "L 437.348495 124.221076 \n",
       "L 447.701 124.372163 \n",
       "L 458.053505 124.515982 \n",
       "L 468.406009 124.653046 \n",
       "L 478.758514 124.78382 \n",
       "L 489.111019 124.908726 \n",
       "L 499.463523 125.028152 \n",
       "L 509.816028 125.14245 \n",
       "L 520.168533 125.251943 \n",
       "L 530.521037 125.356928 \n",
       "L 540.873542 125.457679 \n",
       "L 551.226046 125.554445 \n",
       "L 561.578551 125.647459 \n",
       "\" style=\"fill:none;stroke:#55a868;stroke-dasharray:6.475,2.8;stroke-dashoffset:0;stroke-width:1.75;\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_27\">\n",
       "    <path clip-path=\"url(#pc82c52488d)\" d=\"M 54.305824 318.534545 \n",
       "L 64.658329 228.065309 \n",
       "L 75.010833 190.046333 \n",
       "L 85.363338 170.564397 \n",
       "L 95.715842 159.268902 \n",
       "L 106.068347 152.141482 \n",
       "L 116.420852 147.35779 \n",
       "L 126.773356 143.992472 \n",
       "L 137.125861 141.535563 \n",
       "L 147.478366 139.687275 \n",
       "L 157.83087 138.262007 \n",
       "L 168.183375 137.139869 \n",
       "L 178.53588 136.240621 \n",
       "L 188.888384 135.508914 \n",
       "L 199.240889 134.905575 \n",
       "L 209.593393 134.402242 \n",
       "L 219.945898 133.977974 \n",
       "L 230.298403 133.61704 \n",
       "L 240.650907 133.307434 \n",
       "L 251.003412 133.039865 \n",
       "L 261.355917 132.807053 \n",
       "L 271.708421 132.603229 \n",
       "L 282.060926 132.423774 \n",
       "L 292.413431 132.264952 \n",
       "L 302.765935 132.123716 \n",
       "L 313.11844 131.997564 \n",
       "L 323.470944 131.884421 \n",
       "L 333.823449 131.782559 \n",
       "L 344.175954 131.690525 \n",
       "L 354.528458 131.607095 \n",
       "L 364.880963 131.53123 \n",
       "L 375.233468 131.462041 \n",
       "L 385.585972 131.398767 \n",
       "L 395.938477 131.340753 \n",
       "L 406.290982 131.287432 \n",
       "L 416.643486 131.238311 \n",
       "L 426.995991 131.19296 \n",
       "L 437.348495 131.151002 \n",
       "L 447.701 131.112108 \n",
       "L 458.053505 131.075987 \n",
       "L 468.406009 131.042381 \n",
       "L 478.758514 131.011061 \n",
       "L 489.111019 130.981825 \n",
       "L 499.463523 130.954493 \n",
       "L 509.816028 130.928902 \n",
       "L 520.168533 130.904907 \n",
       "L 530.521037 130.882379 \n",
       "L 540.873542 130.861201 \n",
       "L 551.226046 130.841266 \n",
       "L 561.578551 130.822479 \n",
       "\" style=\"fill:none;stroke:#c44e52;stroke-dasharray:11.2,2.8,1.75,2.8;stroke-dashoffset:0;stroke-width:1.75;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 28.942188 333.36 \n",
       "L 28.942188 7.2 \n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 586.942188 333.36 \n",
       "L 586.942188 7.2 \n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path d=\"M 28.942188 333.36 \n",
       "L 586.942187 333.36 \n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path d=\"M 28.942188 7.2 \n",
       "L 586.942187 7.2 \n",
       "\" style=\"fill:none;\"/>\n",
       "   </g>\n",
       "   <g id=\"legend_1\">\n",
       "    <g id=\"line2d_28\">\n",
       "     <path d=\"M 510.942187 289.002187 \n",
       "L 530.942188 289.002187 \n",
       "\" style=\"fill:none;stroke:#4c72b0;stroke-linecap:round;stroke-width:1.75;\"/>\n",
       "    </g>\n",
       "    <g id=\"line2d_29\"/>\n",
       "    <g id=\"text_13\">\n",
       "     <!-- $u$ -->\n",
       "     <g style=\"fill:#262626;\" transform=\"translate(538.942188 292.502187)scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path d=\"M 428 1388 \n",
       "L 838 3500 \n",
       "L 1416 3500 \n",
       "L 1006 1409 \n",
       "Q 975 1256 961 1147 \n",
       "Q 947 1038 947 966 \n",
       "Q 947 700 1109 554 \n",
       "Q 1272 409 1569 409 \n",
       "Q 2031 409 2368 721 \n",
       "Q 2706 1034 2809 1563 \n",
       "L 3194 3500 \n",
       "L 3769 3500 \n",
       "L 3091 0 \n",
       "L 2516 0 \n",
       "L 2631 550 \n",
       "Q 2388 244 2052 76 \n",
       "Q 1716 -91 1338 -91 \n",
       "Q 878 -91 622 161 \n",
       "Q 366 413 366 863 \n",
       "Q 366 956 381 1097 \n",
       "Q 397 1238 428 1388 \n",
       "z\n",
       "\" id=\"DejaVuSans-Oblique-75\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use transform=\"translate(0 0.3125)\" xlink:href=\"#DejaVuSans-Oblique-75\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"line2d_30\">\n",
       "     <path d=\"M 510.942187 303.680313 \n",
       "L 530.942188 303.680313 \n",
       "\" style=\"fill:none;stroke:#55a868;stroke-dasharray:6.475,2.8;stroke-dashoffset:0;stroke-width:1.75;\"/>\n",
       "    </g>\n",
       "    <g id=\"line2d_31\"/>\n",
       "    <g id=\"text_14\">\n",
       "     <!-- $du/dx$ -->\n",
       "     <g style=\"fill:#262626;\" transform=\"translate(538.942188 307.180313)scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path d=\"M 2675 525 \n",
       "Q 2444 222 2128 65 \n",
       "Q 1813 -91 1428 -91 \n",
       "Q 903 -91 598 267 \n",
       "Q 294 625 294 1247 \n",
       "Q 294 1766 478 2236 \n",
       "Q 663 2706 1013 3078 \n",
       "Q 1244 3325 1534 3454 \n",
       "Q 1825 3584 2144 3584 \n",
       "Q 2481 3584 2739 3421 \n",
       "Q 2997 3259 3138 2956 \n",
       "L 3513 4863 \n",
       "L 4091 4863 \n",
       "L 3144 0 \n",
       "L 2566 0 \n",
       "L 2675 525 \n",
       "z\n",
       "M 891 1350 \n",
       "Q 891 897 1095 644 \n",
       "Q 1300 391 1663 391 \n",
       "Q 1931 391 2161 520 \n",
       "Q 2391 650 2566 903 \n",
       "Q 2750 1166 2856 1509 \n",
       "Q 2963 1853 2963 2188 \n",
       "Q 2963 2622 2758 2865 \n",
       "Q 2553 3109 2194 3109 \n",
       "Q 1922 3109 1687 2981 \n",
       "Q 1453 2853 1288 2613 \n",
       "Q 1106 2353 998 2009 \n",
       "Q 891 1666 891 1350 \n",
       "z\n",
       "\" id=\"DejaVuSans-Oblique-64\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 1625 4666 \n",
       "L 2156 4666 \n",
       "L 531 -594 \n",
       "L 0 -594 \n",
       "L 1625 4666 \n",
       "z\n",
       "\" id=\"DejaVuSans-2f\" transform=\"scale(0.015625)\"/>\n",
       "       <path d=\"M 3841 3500 \n",
       "L 2234 1784 \n",
       "L 3219 0 \n",
       "L 2559 0 \n",
       "L 1819 1388 \n",
       "L 531 0 \n",
       "L -166 0 \n",
       "L 1556 1844 \n",
       "L 641 3500 \n",
       "L 1300 3500 \n",
       "L 1972 2234 \n",
       "L 3144 3500 \n",
       "L 3841 3500 \n",
       "z\n",
       "\" id=\"DejaVuSans-Oblique-78\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use transform=\"translate(0 0.015625)\" xlink:href=\"#DejaVuSans-Oblique-64\"/>\n",
       "      <use transform=\"translate(63.476562 0.015625)\" xlink:href=\"#DejaVuSans-Oblique-75\"/>\n",
       "      <use transform=\"translate(126.855469 0.015625)\" xlink:href=\"#DejaVuSans-2f\"/>\n",
       "      <use transform=\"translate(160.546875 0.015625)\" xlink:href=\"#DejaVuSans-Oblique-64\"/>\n",
       "      <use transform=\"translate(224.023438 0.015625)\" xlink:href=\"#DejaVuSans-Oblique-78\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"line2d_32\">\n",
       "     <path d=\"M 510.942187 318.780313 \n",
       "L 530.942188 318.780313 \n",
       "\" style=\"fill:none;stroke:#c44e52;stroke-dasharray:11.2,2.8,1.75,2.8;stroke-dashoffset:0;stroke-width:1.75;\"/>\n",
       "    </g>\n",
       "    <g id=\"line2d_33\"/>\n",
       "    <g id=\"text_15\">\n",
       "     <!-- $d^2u/dx^2$ -->\n",
       "     <g style=\"fill:#262626;\" transform=\"translate(538.942188 322.280313)scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path d=\"M 1228 531 \n",
       "L 3431 531 \n",
       "L 3431 0 \n",
       "L 469 0 \n",
       "L 469 531 \n",
       "Q 828 903 1448 1529 \n",
       "Q 2069 2156 2228 2338 \n",
       "Q 2531 2678 2651 2914 \n",
       "Q 2772 3150 2772 3378 \n",
       "Q 2772 3750 2511 3984 \n",
       "Q 2250 4219 1831 4219 \n",
       "Q 1534 4219 1204 4116 \n",
       "Q 875 4013 500 3803 \n",
       "L 500 4441 \n",
       "Q 881 4594 1212 4672 \n",
       "Q 1544 4750 1819 4750 \n",
       "Q 2544 4750 2975 4387 \n",
       "Q 3406 4025 3406 3419 \n",
       "Q 3406 3131 3298 2873 \n",
       "Q 3191 2616 2906 2266 \n",
       "Q 2828 2175 2409 1742 \n",
       "Q 1991 1309 1228 531 \n",
       "z\n",
       "\" id=\"DejaVuSans-32\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use transform=\"translate(0 0.765625)\" xlink:href=\"#DejaVuSans-Oblique-64\"/>\n",
       "      <use transform=\"translate(70.924271 39.046875)scale(0.7)\" xlink:href=\"#DejaVuSans-32\"/>\n",
       "      <use transform=\"translate(118.194779 0.765625)\" xlink:href=\"#DejaVuSans-Oblique-75\"/>\n",
       "      <use transform=\"translate(181.573685 0.765625)\" xlink:href=\"#DejaVuSans-2f\"/>\n",
       "      <use transform=\"translate(215.265091 0.765625)\" xlink:href=\"#DejaVuSans-Oblique-64\"/>\n",
       "      <use transform=\"translate(278.741654 0.765625)\" xlink:href=\"#DejaVuSans-Oblique-78\"/>\n",
       "      <use transform=\"translate(342.387487 39.046875)scale(0.7)\" xlink:href=\"#DejaVuSans-32\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"pc82c52488d\">\n",
       "   <rect height=\"326.16\" width=\"558\" x=\"28.942188\" y=\"7.2\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(10, 6))\n",
    "plt.plot(x, u, label='$u$')\n",
    "plt.plot(x, u1, '--', label='$du/dx$')\n",
    "plt.plot(x, u2, '-.', label='$d^2u/dx^2$')\n",
    "plt.legend(loc=0);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Time-Additive Utility"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy.optimize import minimize"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "kappa = 10 / 11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "def U(c):\n",
    "    return -(math.log(c[0]) +  kappa * math.log(c[1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "w = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "cons = ({'type': 'eq', 'fun': lambda c: c[0] + c[1] - w})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "opt = minimize(U, (1, 1), constraints=cons)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "     fun: -3.0747286083026886\n",
       "     jac: array([-0.19091, -0.19091])\n",
       " message: 'Optimization terminated successfully'\n",
       "    nfev: 18\n",
       "     nit: 6\n",
       "    njev: 6\n",
       "  status: 0\n",
       " success: True\n",
       "       x: array([5.23811, 4.76189])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "opt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5.23811, 4.76189])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "opt['x']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.0747286083026886"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "-opt['fun']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Optimal Investment Portfolio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "B = (10, (11, 11))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "S = (10, (20, 5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "M0 = np.array((B[0], S[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "M = np.array((B[1], S[1])).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = 0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "P = np.array((p, 1-p))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "def U(phi):\n",
    "    c1 = np.dot(M, phi)\n",
    "    return -np.dot(P, np.log(c1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.3978952727983707"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "-U((1, 0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.3025850929940455"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "-U((0, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.410140782802518"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "-U((0.5, 0.5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "w = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "cons = ({'type': 'eq',\n",
    "         'fun': lambda phi: np.dot(M0, phi) - w})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "opt = minimize(U, (1, 1), constraints=cons)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "     fun: -2.4183062699261972\n",
       "     jac: array([-1.     , -0.99999])\n",
       " message: 'Optimization terminated successfully'\n",
       "    nfev: 15\n",
       "     nit: 5\n",
       "    njev: 5\n",
       "  status: 0\n",
       " success: True\n",
       "       x: array([0.69442, 0.30558])"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "opt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.69442, 0.30558])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "opt['x']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.4183062699261972"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "-opt['fun']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.4183062699261972"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "-U(opt['x'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([13.75022,  9.16652])"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(M, opt['x'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Time-Additive Expected Utility"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "M0 = np.array((1, B[0], S[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "kappa = 10 / 11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "def U(phi):\n",
    "    c0 = phi[0]\n",
    "    c1 = np.dot(M, phi[1:])\n",
    "    return -(np.log(c0) + kappa * np.dot(P, np.log(c1)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "opt = minimize(U, (1, 1, 1), constraints=cons)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "     fun: -3.1799295980286093\n",
       "     jac: array([-0.19088, -1.90932, -1.90974])\n",
       " message: 'Optimization terminated successfully'\n",
       "    nfev: 32\n",
       "     nit: 8\n",
       "    njev: 8\n",
       "  status: 0\n",
       " success: True\n",
       "       x: array([5.23899, 0.33087, 0.14523])"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "opt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.1799295980286093"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "-opt['fun']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.23898714830318"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "opt['x'][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([6.54422, 4.36571])"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(M, opt['x'][1:])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A Numerical Example I"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = 1 / 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "P = np.array((p, (1-p)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "B1 = np.array((11, 11))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "S1 = np.array((20, 5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "zeta = np.dot(S1 / (B1 + S1), P) / np.dot(B1 / (B1 + S1), P)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7342657342657343"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zeta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "w = 15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "B0 = w / (1 + zeta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8.649193548387098"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "S0 = zeta * B0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6.350806451612904"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "S0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15.000000000000002"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B0 + S0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "i = B1.mean() / B0 - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.2717948717948717"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "mu = np.dot(S1, P) / S0 - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5746031746031743"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sympy as sy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "q = sy.Symbol('q')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "eq = (q * 20 + (1 - q) * 5) / (1 + i) - S0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 11.7943548387097 q - 2.41935483870968$"
      ],
      "text/plain": [
       "11.7943548387097*q - 2.41935483870968"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "q = sy.solve(eq)[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 0.205128205128205$"
      ],
      "text/plain": [
       "0.205128205128205"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "q"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "Q = np.array((q, 1-q))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 8.6491935483871$"
      ],
      "text/plain": [
       "8.64919354838710"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(B1, Q) / (1 + i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 6.3508064516129$"
      ],
      "text/plain": [
       "6.35080645161290"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(S1, Q) / (1 + i)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pricing in Incomplete Markets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = 1 / 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "P = np.array((p, p, p))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [],
   "source": [
    "B1 = np.array((11, 11, 11))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "S1 = np.array((20, 10, 5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [],
   "source": [
    "zeta = np.dot(S1 / (B1 + S1), P) / np.dot(B1 / (B1 + S1), P)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9155274934101636"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zeta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [],
   "source": [
    "w = 15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "B0 = w / (1 + zeta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7.8307411674347165"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [],
   "source": [
    "S0 = zeta * B0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7.169258832565284"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "S0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15.0"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B0 + S0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [],
   "source": [
    "i = B1.mean() / B0 - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.40472016183411985"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [],
   "source": [
    "mu = np.dot(S1, P) / S0 - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6273183796451287"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mu"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Martingale Measures in Incomplete Markets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "qu = sy.Symbol('qu')\n",
    "qm = sy.Symbol('qm')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [],
   "source": [
    "eq = (qu * 20 + qm * 10 + (1 - qu - qm) * 5) / (1 + i) - S0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 3.55942780337942 qm + 10.6782834101383 qu - 3.60983102918587$"
      ],
      "text/plain": [
       "3.55942780337942*qm + 10.6782834101383*qu - 3.60983102918587"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [],
   "source": [
    "Q = sy.solve(eq, set=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "([qm], {(1.01416048550236 - 3.00000000000001*qu,)})"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Q"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A Numerical Example II"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = 1 / 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [],
   "source": [
    "P = np.array((p, p, p))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [],
   "source": [
    "B1 = np.array((11, 11, 11))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [],
   "source": [
    "S1 = np.array((20, 10, 5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [],
   "source": [
    "C1 = np.array((5, 0, 0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [],
   "source": [
    "zeta_1 = (np.dot(S1 / (B1 + S1 + C1), P) /\n",
    "          np.dot(B1 / (B1 + S1 + C1), P))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8862001308044474"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zeta_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [],
   "source": [
    "zeta_2 = (np.dot(C1 / (B1 + S1 + C1), P) /\n",
    "          np.dot(B1 / (B1 + S1 + C1), P))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.09156311314584695"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zeta_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [],
   "source": [
    "w = 15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [],
   "source": [
    "B0 = w / (1 + zeta_1 + zeta_2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7.584325396825396"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [],
   "source": [
    "S0 = zeta_1 * B0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6.721230158730158"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "S0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [],
   "source": [
    "C0 = zeta_2 * B0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6944444444444443"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "C0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14.999999999999998"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B0 + S0 + C0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [],
   "source": [
    "i = B1.mean() / B0 - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.45035971223021587"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [],
   "source": [
    "muS = np.dot(S1, P) / S0 - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7357933579335794"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "muS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [],
   "source": [
    "muC = np.dot(C1, P) / C0 - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.4000000000000004"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "muC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [],
   "source": [
    "M = np.array((B1, S1, C1)).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[11, 20,  5],\n",
       "       [11, 10,  0],\n",
       "       [11,  5,  0]])"
      ]
     },
     "execution_count": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {},
   "outputs": [],
   "source": [
    "M0 = np.array((B0, S0, C0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [],
   "source": [
    "Q = np.linalg.solve(M.T / (1 + i), M0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.20144, 0.34532, 0.45324])"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Q"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 131,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum(Q)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.allclose(np.dot(M.T, Q), M0 * (1 + i))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"http://hilpisch.com/tpq_logo.png\" alt=\"The Python Quants\" width=\"35%\" align=\"right\" border=\"0\"><br>\n",
    "\n",
    "<a href=\"http://tpq.io\" target=\"_blank\">http://tpq.io</a> | <a href=\"http://twitter.com/dyjh\" target=\"_blank\">@dyjh</a> | <a href=\"mailto:training@tpq.io\">training@tpq.io</a>"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
